package com.cskaoyan.kpi.peak;

import com.cskaoyan.kpi.Summary;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

/**
 * @ClassName DailyHourPeakReducer
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/17 9:19
 * @Version V1.0
 **/
public class DailyHourPeakReducer extends Reducer<IntWritable, Text, Summary, Text> {

    @Override
    protected void reduce(IntWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        String date = null;
        int num = 0;
        for (Text value : values) {
            if(num == 0){
                date = value.toString();
            }
            num ++;
        }
        Summary hourPeak = new Summary(null, date, "hourPeak", num + "", key.get() + "");
        context.write(hourPeak, new Text());
    }
}
